/*
	Copyright (C) 2011 Salil Bhagurkar

	This file is part of illusion

	illusion is free software: you can redistribute it and/or modify
	it under the terms of the GNU Lesser General Public License as
	published by the Free Software Foundation, either version 3 of
	the License, or (at your option) any later version.

	illusion is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU Lesser General Public License for more details.

	You should have received a copy of the GNU Lesser General Public
	License along with illusion.
	If not, see <http://www.gnu.org/licenses/>.
*/

#include <klib/lib.h>
#include <kernel/module.h>
#include <kernel/ilapp.h>
#include <kernel/errors.h>
#include <apimod/apimod.h>
#include <kernel/vfs.h>
#include <kernel/input.h>
#include <kernel/ilapp_base.h>

static struct apimod_console *console;
static struct apimod_fs1 *fs1;
static struct apimod_fs *fs;
static struct apimod_base *base;

int ilapp_main()
{
	GETI("console", &console);
	GETI("base", &base);
	GETI("fs1", &fs1);
	GETI("fs", &fs);

	uint_t len;
	char *args = base->get_arguments(&len);
	if(args == null) {
		console->printf("Noting to write!\n");
		return 0;
	}

	uint_t fid;
	base->get_current(&fid);
	fs->change_state(fid, STATE_WRITE);
	fs->write(fid, args, 0, len);
	fs->close(fid);

	return 0;
}
